<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
	<title>统计表1</title>
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
	<link href="/static/basic/plugins/fontawesome-free-5.15.4-web/css/all.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="/static/m.css?v=new2" >
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/webuploader/webuploader.css?v=new2">
</head>
<body>
<div id="window-mmask" class="window-mmask" ><div class="window-mmask-msg" >页面加载中,请稍候...</div></div>
<div id="layout1" class="easyui-layout" data-options="fit:true"  >
	<div data-options="region:'center',title:'表1'" >
		<table id="gridList" ></table>
	</div>
</div>

<div id="searchbar">
	<div class="maction">
		<a href="javascript:void(0)" id="importBtn1" class="easyui-linkbutton webuploader-container" data-options="plain:true,iconCls:'mbutton'">导入excel-覆盖</a>
		<a href="javascript:void(0)" id="importBtn2" class="easyui-linkbutton webuploader-container" data-options="plain:true,iconCls:'mbutton'">导入excel-追加</a>
		<a href="javascript:void(0)" id="btn3" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-trash-alt mbutton color-c5'">删除</a>
		<a href="javascript:void(0)" id="saveButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-save mbutton'">保存</a>
		<a href="javascript:void(0)" id="exportData1" class="easyui-linkbutton" data-options="plain:true,iconCls:'mbutton'">导出数据</a>
	</div>
	<form id="searchForm" >
		<!--Id<input id="search-Id" name="Id" class="easyui-textbox" >
        b<input id="search-b" name="b" class="easyui-textbox" >-->
		<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-search mbutton'" >查询</a>
	</form>
</div>
<script src="/static/basic/plugins/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="/static/extensions/jquery.jdirk.js"></script>
<script src="/static/extensions/jeasyui.extensions.base.loading.js"></script>
<script src="/static/init.js?v=08151"></script>
<script src="/static/searchEdit.js?v=12"></script>
<script src="/static/enum.js"></script>
<script type="text/javascript" src="/static/basic/plugins/webuploader/webuploader.html5only.min.js"></script>
<!-- <script src="/static/basic/plugins/moment.min.js"></script> -->
<script>
	var taskId=$.query.get("taskId");
	var tableName=$.query.get("tableName");
	var reportId=$.query.get("reportId");
	var reportName=decodeURIComponent($.query.get("reportName"));
	var gridMap={
		"excel_data1":{page_id:"482340976511418368",sqlname:"grid_482340976511418368_excel_data1"},
		"excel_data2":{page_id:"483431073571012608",sqlname:"grid_483431073571012608_excel_data2"},
		"excel_data3":{page_id:"484550256149266432",sqlname:"grid_484550256149266432_excel_data3"}
	};
	var page=gridMap[tableName];
	var editRow=null;
	var startTimeout=0;
	//document ready
	$(function(){
		$("#layout1").layout("panel","center").panel("setTitle",reportName);
		//1.先查询任务信息
		grid1=new uniontrip.datagrid.searchEdit({
			idField:'Id',
			page_id:page.page_id,
			grid_id:"gridList",
			sqlname:page.sqlname,
			showCheckbox:false,
			rownumbers:false,
			toolbar_id:"searchbar",
			//initColumnUrl:"/",
			gridParam:{"taskId":taskId,"ascOrDesc":"asc","orderBy":"Id"},
			initColumnParam:{"taskId":taskId,reportId:reportId},
			onClickRow:function(rowIndex, rowData){
				// if(rowData.id!=template_instance_id){
				// 	template_instance_id=rowData.id;
				// 	grid2.loadParam({template_instance_id:template_instance_id});
				// }
			},
			column_formatter:{
				content:function(value,row,index){
					//return value;
					return "<pre style='overflow:hidden'>"+value+"</pre>";
				},
				example:function(value,row,index){
					//return value;
					return "<pre style='overflow:hidden'>"+value+"</pre>";
				},
			},
			searchParamOperator:{
				title:"contain"
			},
		});
		//tab
		$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
		//$('#searchButton2').bind('click',grid2.load);//查询操作绑定事件
		$('#saveButton').bind('click', grid1.accept);//保存datagrid绑定事件
		//$('#saveButton2').bind('click', grid2.accept);//保存datagrid绑定事件
		//row
		//$('#addButton').bind('click', addRow);//新增行绑定事件
		//$('#editButton').bind('click',grid1.editRow);//编辑按钮绑定事件
		//$('#removeButton').bind('click',grid1.remove);//删除行绑定事件
		$('#btn3').bind('click',grid1.remove);//删除行绑定事件
		//$('#btn6').bind('click',grid2.remove);//删除行绑定事件
		//$('#importBtn1').bind('click', function () {

		//});//保存datagrid绑定事件
		//$('#cancelEditButton').bind('click',grid1.cancelEditing);//取消行编辑绑定事件
		$('#insertToData2').bind('click', function(){
			$.post("/compare/insertToData",{taskId:taskId,fromReportId:reportId,toReportId:report2.id},function (result){
				if(result.success){
					info("新增成功");
				}else{
					$.messager.alert("提示", "操作失败！<br>"+result.message);
				}
			});
		});
		$('#insertToData1').bind('click', function(){
			$.post("/compare/insertToData",{taskId:taskId,fromReportId:report2.id,toReportId:reportId},function (result){
				if(result.success){
					info("新增成功");
				}else{
					$.messager.alert("提示", "操作失败！<br>"+result.message);
				}
			});
		});
		$('#exportData1').bind('click', function(){
			$.post("/compare/exportData1",{taskId:taskId,tableName:tableName},function (result){
				if(result.success){
					$.easyui.loading();
					startTimeout=0;
					download(result.data);
				}else{
					$.messager.alert("提示", "操作失败！<br>"+result.message);
				}
			});
		});
		$('#exportData2').bind('click', function(){
			$.post("/compare/exportData2",{taskId:taskId},function (result){
				if(result.success){
					$.easyui.loading();
					startTimeout=0;
					download(result.data);
				}else{
					$.messager.alert("提示", "操作失败！<br>"+result.message);
				}
			});
		});

		$('#exportBtn').bind('click',function(){
			$.post("/compare/exportCompareResult",{taskId:taskId},function (result){
				if(result.success){
					$.easyui.loading();
					startTimeout=0;
					download(result.data);
				}else{
					$.messager.alert("提示", "操作失败！<br>"+result.message);
				}
			});
		});

		$('#stat2').bind('click',function(){
			$.post("/ec/stat/updateData2",{taskId:taskId}, function(result){
				if(result.success){
					//grid2.load();
				}else{
					$.messager.alert("提示", "统计数据失败，请联系管理员！<br>"+result.message);
				}
			});
		});


		//初始化搜索框
		initsearch();
		initWebUploader1();
		initWebUploader2();
		//initWebUploader3();
		//initWebUploader4();




	});
	var mytim;

	function download(fileItemId){
		//clearTimeout(mytim);
		mytim = setTimeout(function(){
			$.post("/file/downloadQuery/"+fileItemId,null,function (result) {
				if(result.success){
					$.easyui.loaded();
					var form = $("<form>",{
						method:"post",
						action:result.data
					});
					form.appendTo('body').submit().remove();
				}else{
					if(startTimeout<60){
						startTimeout++;
						download(fileItemId)
					}else{
						$.easyui.loaded();
						$.messager.alert("提示", "等待超时");
					}
				}

			});
		},1000);
	}
	function initWebUploader1(){
		//初始化Web Uploader
		var uploader = WebUploader.create({

			// 选完文件后，是否自动上传。
			auto: true,
			// 文件接收服务端。
			server: '/compare/importData',

			// 选择文件的按钮。可选。
			// 内部根据当前运行是创建，可能是input元素，也可能是flash.
			pick: {
				id: "#importBtn1"
			},
			formData: {
				//excelConfigId:excelConfigId //非固定值不起作用
			},
			// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false,
			accept: {
				title: 'excel',
				extensions: 'xlsx',//没有测试是否起作用
				mimeTypes:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//这个起作用
			}
		});
		uploader.on('beforeFileQueued', function(file) {
			console.log("beforeFileQueued");
			console.log(file);
			if (file.ext !== 'xlsx') {
				// 文件格式不符合要求，进行处理
				return false;
			}
			uploader.options.formData={taskId:taskId,reportId:reportId,isAppend:0};
			$.easyui.loading();
		});
		// 当有文件被添加进队列的时候
		uploader.on( 'fileQueued', function( file ) {
			console.log("fileQueued");
			console.log(file);
			if (file.ext !== 'xlsx') {
				// 文件格式不符合要求，进行处理
				uploader.removeFile(file, true);
				return false;
			}

		});


		uploader.on( 'uploadSuccess', function( file,response ) {
			console.log(response);
			if(!response.success){
				$.messager.alert("提示", "导入失败！<br>"+response.message);
			}else{
				info("导入成功");
				//自动统计并刷新表格
				$.post("/ec/stat/updateData2",{taskId:taskId}, function(result){
					if(result.success){
						//grid2.load();
					}else{
						$.messager.alert("提示", "统计数据失败，请联系管理员！<br>"+result.message);
					}
				});
			}
			//$("#cert_id").val(response.data[0].item_id);
			//$( '#'+file.id ).find('p.state').text('已上传');
		});

		uploader.on( 'uploadError', function( file ) {
			console.log(file);
			//$( '#'+file.id ).find('p.state').text('上传出错');
		});

		uploader.on( 'uploadComplete', function( file ) {
			$.easyui.loaded();
			//$( '#'+file.id ).find('.progress').fadeOut();
			uploader.reset();
			grid1.load();
		});

		uploader.on('uploadBeforeSend', function(object,data,headers) {
			let access_token=localStorage.getItem("access_token");
			headers.Accept="application/json";
			//headers["X-Requested-With"]="XMLHttpRequest";
			headers.Authorization="Local "+access_token;
			//headers.Authorization=BearerType+access_token;
		});
	}
	function initWebUploader2(){
		//初始化Web Uploader
		var uploader2 = WebUploader.create({

			// 选完文件后，是否自动上传。
			auto: true,
			// 文件接收服务端。
			server: '/compare/importData',

			// 选择文件的按钮。可选。
			// 内部根据当前运行是创建，可能是input元素，也可能是flash.
			pick: {
				id: "#importBtn2"
			},
			formData: {
				//excelConfigId:excelConfigId //非固定值不起作用
			},
			// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false,
			accept: {
				title: 'excel',
				extensions: 'xlsx',//没有测试是否起作用
				mimeTypes:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//这个起作用
			}
		});
		uploader2.on('beforeFileQueued', function(file) {
			if (file.ext !== 'xlsx') {
				// 文件格式不符合要求，进行处理
				return false;
			}
			uploader2.options.formData={taskId:taskId,reportId:reportId,isAppend:1};
			$.easyui.loading();
		});
		// 当有文件被添加进队列的时候
		uploader2.on( 'fileQueued', function( file ) {
			if (file.ext !== 'xlsx') {
				// 文件格式不符合要求，进行处理
				uploader2.removeFile(file, true);
				return false;
			}

		});


		uploader2.on( 'uploadSuccess', function( file,response ) {
			console.log(response);
			if(!response.success){
				$.messager.alert("提示", "导入失败！<br>"+response.message);
			}else{
				info("导入成功");
			}
			//$("#cert_id").val(response.data[0].item_id);
			//$( '#'+file.id ).find('p.state').text('已上传');
		});

		uploader2.on( 'uploadError', function( file ) {
			console.log(file);
			//$( '#'+file.id ).find('p.state').text('上传出错');
		});

		uploader2.on( 'uploadComplete', function( file ) {
			$.easyui.loaded();
			//$( '#'+file.id ).find('.progress').fadeOut();
			uploader2.reset();
			grid1.load();
		});

		uploader2.on('uploadBeforeSend', function(object,data,headers) {
			let access_token=localStorage.getItem("access_token");
			headers.Accept="application/json";
			//headers["X-Requested-With"]="XMLHttpRequest";
			headers.Authorization="Local "+access_token;
			//headers.Authorization=BearerType+access_token;
		});
	}
	function initWebUploader3(){
		//初始化Web Uploader
		var uploader3 = WebUploader.create({

			// 选完文件后，是否自动上传。
			auto: true,
			// 文件接收服务端。
			server: '/compare/importData',

			// 选择文件的按钮。可选。
			// 内部根据当前运行是创建，可能是input元素，也可能是flash.
			pick: {
				id: "#importBtn3"
			},
			formData: {
				//excelConfigId:excelConfigId //非固定值不起作用
			},
			// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false,
			accept: {
				title: 'excel',
				extensions: 'xlsx',//没有测试是否起作用
				mimeTypes:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//这个起作用
			}
		});
		uploader3.on('beforeFileQueued', function(file) {
			if (file.ext !== 'xlsx') {
				// 文件格式不符合要求，进行处理
				return false;
			}
			uploader3.options.formData={taskId:taskId,reportId:report2.id,isAppend:0};
			$.easyui.loading();
		});
		// 当有文件被添加进队列的时候
		uploader3.on( 'fileQueued', function( file ) {
			if (file.ext !== 'xlsx') {
				// 文件格式不符合要求，进行处理
				uploader3.removeFile(file, true);
				return false;
			}

		});


		uploader3.on( 'uploadSuccess', function( file,response ) {
			console.log(response);
			if(!response.success){
				$.messager.alert("提示", "导入失败！<br>"+response.message);
			}else{
				info("导入成功");
			}
			//$("#cert_id").val(response.data[0].item_id);
			//$( '#'+file.id ).find('p.state').text('已上传');
		});

		uploader3.on( 'uploadError', function( file ) {
			console.log(file);
			//$( '#'+file.id ).find('p.state').text('上传出错');
		});

		uploader3.on( 'uploadComplete', function( file ) {
			$.easyui.loaded();
			//$( '#'+file.id ).find('.progress').fadeOut();
			uploader3.reset();
			//grid2.load();
		});

		uploader3.on('uploadBeforeSend', function(object,data,headers) {
			let access_token=localStorage.getItem("access_token");
			headers.Accept="application/json";
			//headers["X-Requested-With"]="XMLHttpRequest";
			headers.Authorization="Local "+access_token;
			//headers.Authorization=BearerType+access_token;
		});
	}
	function initWebUploader4(){
		//初始化Web Uploader
		var uploader4 = WebUploader.create({

			// 选完文件后，是否自动上传。
			auto: true,
			// 文件接收服务端。
			server: '/compare/importData',
			// 选择文件的按钮。可选。
			pick: {
				id: "#importBtn4"
			},
			formData: {
				//excelConfigId:excelConfigId //非固定值不起作用
			},
			// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false,
			accept: {
				title: 'excel',
				extensions: 'xlsx',//没有测试是否起作用
				mimeTypes:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//这个起作用
			}
		});
		uploader4.on('beforeFileQueued', function(file) {
			if (file.ext !== 'xlsx') {
				// 文件格式不符合要求，进行处理
				return false;
			}
			uploader4.options.formData={taskId:taskId,reportId:report2.id,isAppend:1};
			$.easyui.loading();
		});
		// 当有文件被添加进队列的时候
		uploader4.on( 'fileQueued', function( file ) {
			if (file.ext !== 'xlsx') {
				// 文件格式不符合要求，进行处理
				uploader4.removeFile(file, true);
				return false;
			}

		});


		uploader4.on( 'uploadSuccess', function( file,response ) {
			if(!response.success){
				$.messager.alert("提示", "导入失败！<br>"+response.message);
			}else{
				info("导入成功");
			}
			//$("#cert_id").val(response.data[0].item_id);
			//$( '#'+file.id ).find('p.state').text('已上传');
		});

		uploader4.on( 'uploadError', function( file ) {
			console.log(file);
			//$( '#'+file.id ).find('p.state').text('上传出错');
		});

		uploader4.on( 'uploadComplete', function( file ) {
			$.easyui.loaded();
			//$( '#'+file.id ).find('.progress').fadeOut();
			uploader4.reset();
			//grid2.load();
		});

		uploader4.on('uploadBeforeSend', function(object,data,headers) {
			let access_token=localStorage.getItem("access_token");
			headers.Accept="application/json";
			//headers["X-Requested-With"]="XMLHttpRequest";
			headers.Authorization="Local "+access_token;
			//headers.Authorization=BearerType+access_token;
		});
	}
	function onDeleteRow2(){
		gridConfirm(grid1.grid,"是否确认删除",function (row){
			$.post("/authenticated/wx/msg/templateInstance/delete",{"id":row.id},function(result){
				if(result.success){
					info("删除成功！");
					grid1.load();
				}else{
					$.messager.alert("提示", "删除失败！<br>"+result.message);
				}
			});
		});
	}

	function save(){
		//if($("#form1").form('enableValidation').form('validate')){
		$.post(saveUrl,$("#form1").serializeObject(),function(result){
			if(result.success){
				info( "保存成功！");
				EditDialogModifyMchId.dialog('close');
				grid1.load();
			}else{
				$.messager.alert("提示", "保存失败！<br>"+result.message);
			}
		});
		//}
	}
	/**
	 * 新增一行
	 */
	function addRow(){
//ROW
		var newRowData={id:guid()};//初始化行数据,creator_id:sessionuser.id,creator_name:sessionuser.nickname,create_time:moment().format('YYYY-MM-DD')
		grid1.grid.datagrid('append',newRowData);
		//tab
		parent.addTab("新增","/view/sys/wx/msg_templateform.html");
	}
	function onUpdate(){
		var selectRows=grid1.grid.datagrid('getSelections');
		if(selectRows.length>0){
			parent.addTab("编辑["+selectRows[0].id+"]","/view/sys/wx/msg_templateform.html?id="+selectRows[0].id);
		}else{
			$.messager.alert("提示", "请选择一条数据！");
		}
	}
	/**
	 * 删除提交
	 * @param selectRow
	 */
	function deleteSubmit(selectRow){
		$.post("/authenticated/ajax/update/grid_wx_msg_template-delete",JSON.stringify({ids:[selectRow.id]}),function(result){
			if(result.status==200){
				$.messager.alert("提示", "删除成功！");
				grid1.load();
			}
		});
	}

	function onDeleteRow(){
		gridConfirm(grid1.grid,"是否确认删除",deleteRow);
	}
	function deleteRow(row){
		$.post("/authenticated/xx/delete",JSON.stringify({"id":row.id}),function(result){
			if(result.status==200){
				$.messager.alert("提示", "删除成功！");
				grid1.load();
			}else{
				$.messager.alert("提示", "删除失败！<br>"+result.message);
			}
		});
	}


	/**
	 * 初始化搜索条件
	 */
	function initsearch(){
		/*$('#search-product_class_id').combotree({
            panelHeight:'auto',
            icons: [{
                iconCls:'icon-clear',
                handler:function(){
                    $('#search-product_class_id').combotree('clear');
                }
            }],
            data:grid1.combotreeDatas.product_class_id
        });
        //初始化combobox例子
        $('#search-status').combobox({
            panelHeight:'auto',
            editable:false,
            valueField:'codeValue',
            textField:'codeName',
            icons: [{
                iconCls:'icon-clear',
                handler:function(e){
                    $(e.data.target).combobox('clear');
                }
            }],
            data:grid1.comboboxDatas.status
        });*/
	}
</script>
</body>
</html>